﻿Imports TBCC.UtilityMobile
Public Class ProjectImageService

    Public Sub New()

    End Sub

    ''' <summary>
    ''' 新增工程图
    ''' </summary>
    ''' <param name="pii"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function Create(ByVal pii As ProjectImageItem) As Integer
        Dim strSql As String
        strSql = "Insert Into tbccProjectImages(imageID,projectID,Imagename,listNo,imagePath) Values(?p0,?p1,?p2,?p3,?p4)"

        Dim p(4) As MySql.Data.MySqlClient.MySqlParameter
        p(0) = New MySql.Data.MySqlClient.MySqlParameter
        p(0).ParameterName = "p0" : p(0).Value = pii.ImageID

        p(1) = New MySql.Data.MySqlClient.MySqlParameter
        p(1).ParameterName = "p1" : p(1).Value = pii.projectID

        p(2) = New MySql.Data.MySqlClient.MySqlParameter
        p(2).ParameterName = "p2" : p(2).Value = pii.imageName

        p(3) = New MySql.Data.MySqlClient.MySqlParameter
        p(3).ParameterName = "p3" : p(3).Value = pii.ImageOrder

        p(4) = New MySql.Data.MySqlClient.MySqlParameter
        p(4).ParameterName = "p4" : p(4).Value = pii.imagePath

        Return SqlHelper.ExecuteNonQuery(strSql, p)

    End Function

    ''' <summary>
    ''' 修改工程图信息
    ''' </summary>
    ''' <param name="pii"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function Update(ByVal pii As ProjectImageItem) As Integer
        Dim strSql As String
        strSql = "Update tbccProjectImages Set imageName=?p0,listNo=?p1,imagePath=?p2 where imageID=?p3"

        Dim p(3) As MySql.Data.MySqlClient.MySqlParameter
        p(0) = New MySql.Data.MySqlClient.MySqlParameter
        p(0).ParameterName = "p0" : p(0).Value = pii.imageName

        p(1) = New MySql.Data.MySqlClient.MySqlParameter
        p(1).ParameterName = "p1" : p(1).Value = pii.ImageOrder

        p(2) = New MySql.Data.MySqlClient.MySqlParameter
        p(2).ParameterName = "p2" : p(2).Value = pii.imagePath

        p(3) = New MySql.Data.MySqlClient.MySqlParameter
        p(3).ParameterName = "p3" : p(3).Value = pii.ImageID

        Return SqlHelper.ExecuteNonQuery(strSql, p)
    End Function


    ''' <summary>
    ''' 删除工程图
    ''' </summary>
    ''' <param name="pii"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function Delete(ByVal pii As ProjectImageItem) As Integer
        Dim tic As New TranstrationItem()

        Dim strSql As String
        strSql = "Delete From tbccProjectImages Where projectID=?p0 And imageID=?p1"

        Dim p(1) As MySql.Data.MySqlClient.MySqlParameter

        p(0) = New MySql.Data.MySqlClient.MySqlParameter
        p(0).ParameterName = "p0" : p(0).Value = pii.projectID

        p(1) = New MySql.Data.MySqlClient.MySqlParameter
        p(1).ParameterName = "p1" : p(1).Value = pii.ImageID

        tic.Add(strSql, p)

        strSql = "Delete From tbccImagecontrols where projectID=?p0 and imageID=?p1"
        Dim p2(1) As MySql.Data.MySqlClient.MySqlParameter

        p2(0) = New MySql.Data.MySqlClient.MySqlParameter
        p2(0).ParameterName = "p0" : p2(0).Value = pii.projectID

        p2(1) = New MySql.Data.MySqlClient.MySqlParameter
        p2(1).ParameterName = "p1" : p2(1).Value = pii.ImageID
        tic.Add(strSql, p2)


        Return SqlHelper.ExecuteTranstration(tic)


        'Return SqlHelper.ExecuteNonQuery(strSql, p)

    End Function

    ''' <summary>
    ''' 获取指定工程的工程图列表
    ''' </summary>
    ''' <param name="projectID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetList(ByVal projectID As String) As IList(Of ProjectImageItem)
        Dim il As IList(Of ProjectImageItem)
        il = New List(Of ProjectImageItem)

        Dim strSql As String
        strSql = "Select * From tbccProjectImages Where projectID=?p0 Order by ListNo"

        Dim p(0) As MySql.Data.MySqlClient.MySqlParameter
        p(0) = New MySql.Data.MySqlClient.MySqlParameter
        p(0).ParameterName = "p0" : p(0).Value = projectID

        Dim ds As DataSet
        ds = TBCC.UtilityMobile.SqlHelper.ExecuteDataset(strSql, p)

        For Each r As DataRow In ds.Tables(0).Rows
            Dim pii As New ProjectImageItem
            pii.projectID = r("projectID")
            pii.imageName = r("imageName")
            pii.ImageOrder = r("listNo")
            pii.imagePath = r("imagePath")
            pii.ImageID = r("imageID")

            il.Add(pii)
        Next

        Return il
    End Function

End Class
